package org.tc.shopmall.service.impl;

import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.tc.shopmall.entity.ShoppingTest;
import org.tc.shopmall.mapper.ShoppingMapper;
import org.tc.shopmall.service.ShoppingService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
public class ShoppingServiceImpl implements ShoppingService {
    @Autowired
    private ShoppingMapper shoppingMapper;
    @Override
    public HashMap<String, ShoppingTest> QueryAllOrder(Integer userid) {
        List<ShoppingTest> list = shoppingMapper.QueryAllOrder(userid);
        HashMap<String, ShoppingTest> stringListHashMap = new HashMap<>();
        for (ShoppingTest shoppingTest : list) {
            if(stringListHashMap.get(shoppingTest.getId()+"") == null){
                List<ShoppingTest> listNew = new ArrayList<>();
                ShoppingTest s = new ShoppingTest();
                s.setName(shoppingTest.getName());
                s.setPath(shoppingTest.getPath());
                s.setAdress(shoppingTest.getAdress());
                s.setNumber(shoppingTest.getNumber());
                s.setState(shoppingTest.getState());
                s.setCommodityid(shoppingTest.getCommodityid());
                s.setStoreid(shoppingTest.getStoreid());
                listNew.add(s);
                ShoppingTest s1 = shoppingTest;
                s1.setShoppingTestList(listNew);
                stringListHashMap.put(shoppingTest.getId()+"",s1);
            }else{
                ShoppingTest shoppingTest1 = stringListHashMap.get(shoppingTest.getId() + "");
                ShoppingTest s = new ShoppingTest();
                s.setName(shoppingTest.getName());
                s.setPath(shoppingTest.getPath());
                s.setAdress(shoppingTest.getAdress());
                s.setNumber(shoppingTest.getNumber());
                s.setState(shoppingTest.getState());
                s.setCommodityid(shoppingTest.getCommodityid());
                s.setStoreid(shoppingTest.getStoreid());
                List<ShoppingTest> shoppingTestList = shoppingTest1.getShoppingTestList();
                shoppingTestList.add(s);
                stringListHashMap.put(shoppingTest.getId()+"",shoppingTest1);
            }
        }
        System.out.println(stringListHashMap.size());
        return stringListHashMap;
    }

    @Override
    public HashMap<String, ShoppingTest> QueryOrdertoState(Integer userid, Integer state) {
        List<ShoppingTest> list = shoppingMapper.QueryOrdertoState(userid, state);
        HashMap<String, ShoppingTest> stringListHashMap = new HashMap<>();
        for (ShoppingTest shoppingTest : list) {
            if(stringListHashMap.get(shoppingTest.getId()+"") == null){
                List<ShoppingTest> listNew = new ArrayList<>();
                ShoppingTest s = new ShoppingTest();
                s.setName(shoppingTest.getName());
                s.setPath(shoppingTest.getPath());
                s.setAdress(shoppingTest.getAdress());
                s.setNumber(shoppingTest.getNumber());

                listNew.add(s);
                ShoppingTest s1 = shoppingTest;
                s1.setShoppingTestList(listNew);
                stringListHashMap.put(shoppingTest.getId()+"",s1);
            }else{
                ShoppingTest shoppingTest1 = stringListHashMap.get(shoppingTest.getId() + "");
                ShoppingTest s = new ShoppingTest();
                s.setName(shoppingTest.getName());
                s.setPath(shoppingTest.getPath());
                s.setAdress(shoppingTest.getAdress());
                s.setNumber(shoppingTest.getNumber());
                List<ShoppingTest> shoppingTestList = shoppingTest1.getShoppingTestList();
                shoppingTestList.add(s);
                stringListHashMap.put(shoppingTest.getId()+"",shoppingTest1);
            }
        }
        System.out.println(stringListHashMap.size());
        return stringListHashMap;
    }
}
